

// 路径
import path from "path-browserify";

/********************** 类型定义 ********************/
type RecommendInfo<Item> = {
    imgRootPath: string,
    list: Array<Item>
}

type RecommendItem = {
    img: string,
    name: string
}

/*********************** 代码实现 *******************/

// 推荐数据信息
const recommendInfo: RecommendInfo<RecommendItem> = {
    // 对应的商品图片根路径 （ 具体商品图片路径 = imgRootPath + img ）
    imgRootPath: '/img/product_simple/',
    list: [
        {
            "img": "白牡丹.png",
            "name": "白牡丹"
        },
        {
            "img": "贡眉.png",
            "name": "贡眉"
        },
        {
            "img": "寿眉.png",
            "name": "寿眉"
        },
        {
            "img": "礼盒.png",
            "name": "礼盒"
        },
        {
            "img": "白毫银针.png",
            "name": "白毫银针"
        },
        {
            "img": "寿眉.png",
            "name": "寿眉"
        }
    ]
}

/**
 * 推荐数据转换
 * @param recommendInfo 
 * @returns 
 */
function convertRecommend(recommendInfo: RecommendInfo<RecommendItem>): Array<RecommendItem> {
    const imgRootPath = recommendInfo.imgRootPath;

    return recommendInfo.list.map(item => {
        // 图片资源
        item.img = path.join(imgRootPath, item.img)
        return item
    })
}
export default convertRecommend(recommendInfo)